//实例化一个 buffer 对象 buf1
let buf1 = Buffer.alloc(256)
buf1[0] = 0
console.log(buf1.length);
console.log(buf1);

//通过循环初始化 buf1 的每个字节
let num = 1
for (let i = 1; i < buf1.length; i++) {
  buf1[i] = num
  num++
}
console.log(buf1);

//对 buf1 做切片操作
let buf2 = buf1.slice(buf1.length - 10);
console.log(buf2);
console.log(buf2.length);

//对 buf2 做填充操作
buf2.fill(0)
console.log(buf2);

//用数组（数组内容随意）初始化 buf3
let buf3_cont = [1,2,3,8,4,5,6]
let buf3 = Buffer.from(buf3_cont)
console.log(buf3);
console.log(buf3.length);

//用字符串（字符串内容随意）初始化 buf4
let buf4_cont = 'hello world'
let buf4 = Buffer.from(buf4_cont)
console.log(buf4);
console.log(buf4.length);
//打印 buf4 字符串
console.log(buf4.toString());

//将 buf4 的内容复制到 buf3 中
buf4.copy(buf3)
console.log(buf3);
console.log(buf3.length);
console.log(buf3.toString());